package com.zjy.web.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import com.zjy.web.intecepter.CollectorInterceptor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author zhangjianyu
 * email: 578547270@qq.com
 * create_time: 2024-10-22 11:33
 * description:
 */
@Slf4j
@AutoConfiguration
@RequiredArgsConstructor
public class SecurityConfig implements WebMvcConfigurer {

    private final CollectorInterceptor collectorInterceptor;

    /**
     * 注册sa-token的拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册路由拦截器
        registry.addInterceptor(new SaInterceptor(handler -> StpUtil.checkLogin()))
                .addPathPatterns("/**")
                .excludePathPatterns("/**/passUrl/**");

        registry.addInterceptor(collectorInterceptor)
                .addPathPatterns("/**");
    }
}
